import {NextResponse} from "next/server";

// 模拟数据
let comments = [
    { id: 1, text: '这是第一条评论', author: '用户A' },
    { id: 2, text: '这是第二条评论', author: '用户B' },
]

export async function GET() {
    return NextResponse.json(comments);
}

export async function POST(request: Request) {
    const {text} = await request.json()

    // 模拟存储
    const newComment = {
        id: comments.length + 1,
        text,
        author: '当前用户',
    }

    comments.push(newComment)

    return NextResponse.json(newComment, {status: 201})
}